<cfcomponent output="false">
	
	<!--- --->
	
	<cffunction name="getDate" access="public" output="false" returntype="string">
		
		<cfset var local = {} />
						
		<cfreturn dateFormat(applyLocalization(now()),'mm/dd/yyyy') />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="getTime" access="public" output="false" returntype="string">

		<cfreturn timeFormat(applyLocalization(now()),'HH:mm:ss') />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="applyTimezone" access="public" output="false" returntype="string">
		<cfargument name="datetime" required="true"  hint="GMT mm/dd/yyyy HH:nn:ss" />

		<cfset var local = {} />

		<cfset local.delta = listGetAt(request.session.user.timezone,1,":") />
		<cfif listGetAt(request.session.user.timezone,2,":") neq 0>
			<cfset local.delta = local.delta + (listGetAt(request.session.user.timezone,2,":") / 60) />
		</cfif>
		<cfset local.delta = local.delta * 60 />
		
		<cfset local.datetime = dateTimeFormat(dateAdd('n',local.delta,arguments.datetime),"mm/dd/yyyy HH:nn:ss") />
		
		<cfreturn local.datetime />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="applyDST" access="public" output="false" returntype="string">
		<cfargument name="datetime" required="true"  hint="localtime mm/dd/yyyy HH:nn:ss" />

		<cfset var local = {} />
		
		<cfset local.datetime = arguments.datetime />
		
		<cfset local.offset = 0 />
		
		<cfif request.session.user.dst eq 1>
			<cfset local.options = $.run.it('optionService.getOptions',{key="calendar"}) />
			
			<cfloop list="#local.options.dstString#" index="local.i" item="local.item" delimiters="|">
				<cfset local.rangeStart = listGetAt(local.item,1,"-") />
				<cfset local.rangeEnd = listGetAt(local.item,2,"-") />
				
				<!--- if 01/01 or 12/31 don't use 2am since it carries over from previous/future year --->
				<cfif local.rangeStart eq "01/01">
					<cfset local.rangeStart = local.rangeStart & "/#year(arguments.datetime)# 00:00:00">
				<cfelse>
					<cfset local.rangeStart = local.rangeStart & "/#year(arguments.datetime)# 02:00:00">
				</cfif>
				
				<cfif local.rangeEnd eq "12/31">
					<cfset local.rangeEnd = local.rangeEnd & "/#year(arguments.datetime)# 23:59:59" />
				<cfelse>
					<cfset local.rangeEnd = local.rangeEnd & "/#year(arguments.datetime)# 02:00:00" />
				</cfif>
				
				<!--- see if date falls withing dst range --->
				<cfif dateCompare(arguments.datetime,local.rangeStart) gte 0 and dateCompare(arguments.datetime,local.rangeEnd) eq -1>
					<cfset local.offset = 1 />
				</cfif>
			</cfloop>
		</cfif>
		
		<cfset local.datetime = dateTimeFormat(dateAdd('h',local.offset,arguments.datetime),"mm/dd/yyyy HH:nn:ss") />

		<cfreturn local.datetime />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="applyLocalization" access="public" output="false" returntype="string">
		<cfargument name="datetime" required="true"  hint="GMT mm/dd/yyyy HH:nn:ss" />
		
		<cfif len(arguments.dateTime) eq 10>
			<cfset arguments.dateTime = arguments.dateTime & ' 00:00:00' />
		</cfif>
		
		<cfreturn applyDST(applyTimezone(arguments.datetime)) />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="localToUTC" access="public" output="false" returntype="string">
		<cfargument name="datetime" required="true" hint="localtime mm/dd/yyyy HH:nn:ss" />
		
		<cfset var local = {} />
		
		<cfset local.year = year(arguments.datetime) />
		
		<cfset local.delta = listGetat(request.session.user.timezone,1,":") />
		<cfif listGetAt(request.session.user.timezone,2,":") neq 0>
			<cfset local.delta = local.delta + (listGetAt(request.session.user.timezone,2,":") / 60) />
		</cfif>
		<cfset local.delta = local.delta * 60 />
		
		<cfif request.session.user.dst eq 1><!--- figure out DST date range for that year --->

			<cfset local.options = $.run.it('optionService.getOptions',{key="calendar"}) />
			<cfset local.dstOffset = 0 />
			<cfloop list="#local.options.dstString#" index="local.i" item="local.item" delimiters="|">
				<cfset local.rangeStart = listGetAt(local.item,1,"-") />
				<cfset local.rangeEnd = listGetAt(local.item,2,"-") />
				
				<!--- if 01/01 or 12/31 don't use 2am since it carries over from previous/future year --->
				<cfif local.rangeStart eq "01/01">
					<cfset local.rangeStart = local.rangeStart & "/#year(arguments.datetime)# 00:00:00">
				<cfelse>
					<cfset local.rangeStart = local.rangeStart & "/#year(arguments.datetime)# 02:00:00">
				</cfif>
				
				<cfif local.rangeEnd eq "12/31">
					<cfset local.rangeEnd = local.rangeEnd & "/#year(arguments.datetime)# 23:59:59" />
				<cfelse>
					<cfset local.rangeEnd = local.rangeEnd & "/#year(arguments.datetime)# 02:00:00" />
				</cfif>
				
				<!--- see if date falls withing dst range --->
				<cfif dateCompare(arguments.datetime,local.rangeStart) gte 0 and dateCompare(arguments.datetime,local.rangeEnd) eq -1>
					<cfset local.dstOffset = 60 />
				</cfif>
			</cfloop>
			
			<cfset local.delta = local.delta + local.dstOffset />
		</cfif>
		
		<cfset local.datetime = dateTimeFormat(dateAdd('n',local.delta * -1, arguments.datetime),"yyyy-mm-dd HH:nn:ss") />

		<cfreturn local.datetime />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="dateTimeFormat" access="public" output="false" returntype="string">
		<cfargument name="datetime" required="true" hint="localtime mm/dd/yyyy HH:nn:ss" />

		<cfreturn dateFormat(arguments.datetime,'mm/dd/yyyy') & ' #timeFormat(arguments.datetime,"HH:mm:ss")#' />

	</cffunction>
	
	<!--- --->

</cfcomponent>